using System;
using System.Collections.Generic;
using System.Text;
using Reflector.Framework;
using Reflector;
using Reflector.CodeMetrics;
using Reflector.CodeModel;

namespace TestAssistance
{
    public static class ReflectorAssistant
    {

        private static IServiceProvider _Application;

        public static IServiceProvider Application
       {
       	    get
       	    {
                if (_Application == null)
                {
                    foreach (Type type in typeof(IPackage).Assembly.GetTypes())
                    {
                        Type[] interfaces = type.GetInterfaces();
                        if ((interfaces.Length == 2) && (Array.IndexOf(interfaces, Type.GetType("System.IServiceProvider")) != -1) && (Array.IndexOf(interfaces, Type.GetType("System.IDisposable")) != -1))
                        {
                            _Application = (IServiceProvider)Activator.CreateInstance(type, new object[] { null });
                            break;
                        }
                    }
                }
                return _Application;
       	    }
       }

        private static ReflectorServices _ReflectorServices;
        public static ReflectorServices ReflectorServices
       {
           get
           {
               if (_ReflectorServices == null)
               {
                   System.Reflection.ConstructorInfo Constructor = typeof(Reflector.Framework.ReflectorServices).GetConstructors(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)[0];
                   _ReflectorServices = (Reflector.Framework.ReflectorServices)Constructor.Invoke(new Object[1] { ReflectorAssistant.Application });
               }
               return _ReflectorServices;
           }
       }
    }
}
